#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   deploy.py
@Time    :   2024/01/08 10:04:57
@Author  :   Robert
@Version :   1.0
@Contact :   robert.wu@tomra.com
@Desc    :   
'''

import os
import json

if __name__ == '__main__':
    export = '''python src/clas/tools/export_model.py -c src/clas/config.yaml -o Global.pretrained_model=data/models/MobileNetV1_x0_25/best_model -o Global.save_inference_dir=data/models/inference'''
    os.system(export)
    os.mkdir('data/deploy')
    opt = '''./src/clas/opt_v2_12  --model_dir=data/models/inference --optimize_out_type=naive_buffer --optimize_out=data/deploy/model --valid_targets=android_nnapi,arm'''
    os.system(opt)    
    with open('data/label_list.txt', 'r') as f:
        lines = f.readlines()
    labels = [x.strip().split(' ')[1] for x in lines]
    
    with open('src/model_config_template.json', 'r') as f:
        data = json.load(f)
    data['labels'] = labels
    with open('data/deploy/model_config.json', 'w') as f:
        json.dump(data, f, indent=2)
    